home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 February: Tool Chest / Apple Developer CD Series Tool Chest February 1996 (Apple Computer)(1996).iso / Tool Chest / Testing & Debugging / General tools / Audit app & dcmd / Src / AuditFileDialog.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-17  |  6.7 KB  |  312 lines  |  [TEXT/KAHL]

  1. /*                                AuditFileDialog.c                                */
  2. /*
  3.  * AuditFileDialog.c
  4.  * Copyright © 1992-93, Apple Computer Inc. All Rights Reserved.
  5.  * Programmed by Martin Minow,
  6.  *    Internet:    minow@apple.com
  7.  *    AppleLink:    MINOW
  8.  * Version of January 22, 1993
  9.  *
  10.  * File Dialog for Audit display. This replaces the SFPutFile dialog, adding a
  11.  * TextEdit field for the Audit Selector and a checkbox for "initially enabled."
  12.  * See Inside Mac Files (3-21) for details.
  13.  *
  14.  * Edit History
  15.  *    93.01.14 MM        First public release
  16.  *    93.07.09 MM        Reformatted for 80-column page. Added a TextEdit field for
  17.  *                    the number of lines to remember in the display log.
  18.  */
  19. #include "DisplayAudit.h"
  20. #include <StandardFile.h>
  21.  
  22. /*
  23.  * Standard File dialog items. This follows the layout of the old Standard File
  24.  * (-3999) DITL. Our private items are at the end.
  25.  */
  26. enum {
  27.     kSFSaveButton = 1,
  28.     kSFCancelButton,
  29.     kSFSaveAsStaticText,
  30.     kSFVolumeUser,
  31.     kSFEjectButton,
  32.     kSFDriveButton,
  33.     kSFFileNameTextEdit,
  34.     kSFFileListUser,
  35.     kSFItemSelectorTextEdit,
  36.     kSFItemSelectorStaticText,
  37.     kSFItemAuditRecordsTextEdit,
  38.     kSFItemAuditRecordsStaticText,
  39.     kSFItemLogLinesTextEdit,
  40.     kSFItemLogLinesStaticText,
  41.     kSFItemEnabledCheckBox,
  42.     kSFItemFontPopupMenu,
  43.     kSFItemFontSizePopupMenu
  44. };
  45. enum {
  46.     kFirstTime            = -1    /* the first time our hook it's passed a -1        */
  47. };
  48.  
  49. static pascal short            PutDialogFilter(
  50.         short                    itemHit,
  51.         DialogPtr                theDialog
  52.     );
  53.  
  54. /*
  55.  * AuditFileDialog updates the global parameter resource.
  56.  */
  57. void
  58. AuditFileDialog(
  59.         short                            dialogID,
  60.         ConstStr255Param                promptString,
  61.         ConstStr255Param                originalName,
  62.         SFReply                            *reply
  63.     )
  64. {
  65.         Point                            where;
  66.         DialogTHndl                        dialogHdl;
  67.         Rect                            box;
  68.  
  69.         /*
  70.          * Center the dialog
  71.          */
  72.         dialogHdl = (DialogTHndl) GetResource('DLOG', dialogID);
  73.         if (dialogHdl == NULL) {                        /* No resource!            */
  74.             Failure(resNotFound, kErrCreateAuditRecord);
  75.             SetPt(&where, 80, 80);
  76.         }
  77.         else {
  78.             box = (**dialogHdl).boundsRect;                /* Dialog shape            */
  79.             ReleaseResource((Handle) dialogHdl);
  80.             where.h =
  81.                 (width(qd.screenBits.bounds) - width(box)) / 2;
  82.             where.v = 
  83.                 ((height(qd.screenBits.bounds) - GetMBarHeight()) / 3)
  84.                 + GetMBarHeight()
  85.                 - (height(box) / 3);
  86.         }
  87.         SFPPutFile(
  88.             where,
  89.             promptString,
  90.             originalName,
  91.             (DlgHookProcPtr) PutDialogFilter,    /* Dialog item filter            */
  92.             reply,
  93.             dialogID,
  94.             NULL                                /* No Modal Dialog Filter        */
  95.         );
  96.         gParameterUpdateNeeded = TRUE;
  97. }
  98.  
  99. static pascal short
  100. PutDialogFilter(
  101.         short                        itemHit,
  102.         DialogPtr                    theDialog
  103.     )
  104. {
  105.         short                        itemType;
  106.         Handle                        itemHandle;
  107.         Rect                        itemRect;
  108.         short                        i;
  109.         short                        nMenuItems;
  110.         short                        selectedSize;
  111.         short                        parmFontNum;
  112.         Str255                        work;
  113.         Str15                        fontSizeText;
  114. #define DIALOG    (* ((DialogPeek) theDialog))
  115.  
  116.         switch (itemHit) {
  117.         case kFirstTime:
  118.             /*
  119.              * Copy the audit selector from the global storage to the dialog item.
  120.              */
  121.             work[0] = 4;
  122.             BlockMove(&PARM.auditIdent, &work[1], 4);
  123.             for (i = 1; i <= 4; i++) {
  124.                 if (work[i] < ' ') {
  125.                     work[0] = i - 1;
  126.                     break;
  127.                 }
  128.             }
  129.             GetDItem(
  130.                 theDialog,
  131.                 kSFItemSelectorTextEdit,
  132.                 &itemType,
  133.                 &itemHandle,
  134.                 &itemRect
  135.             );
  136.             SetIText(itemHandle, work);
  137.             /*
  138.              * Set the log records field.
  139.              */
  140.             GetDItem(
  141.                 theDialog,
  142.                 kSFItemAuditRecordsTextEdit,
  143.                 &itemType,
  144.                 &itemHandle,
  145.                 &itemRect
  146.             );
  147.             NumToString(PARM.auditRecords, work);
  148.             SetIText(itemHandle, work);
  149.             /*
  150.              * Set the log display lines field.
  151.              */
  152.             GetDItem(
  153.                 theDialog,
  154.                 kSFItemLogLinesTextEdit,
  155.                 &itemType,
  156.                 &itemHandle,
  157.                 &itemRect
  158.             );
  159.             NumToString(PARM.logDisplayLines, work);
  160.             SetIText(itemHandle, work);
  161.             /*
  162.              * Set the checkbox status.
  163.              */
  164.             GetDItem(
  165.                 theDialog,
  166.                 kSFItemEnabledCheckBox,
  167.                 &itemType,
  168.                 &itemHandle,
  169.                 &itemRect
  170.             );
  171.             SetCtlValue((ControlHandle) itemHandle, PARM.enableAudit);
  172.             /*
  173.              * Set the font name popup menu
  174.              */
  175.             nMenuItems = CountMItems(gFontMenu);
  176.             for (i = 1; i <= nMenuItems; i++) {
  177.                 GetItem(gFontMenu, i, work);
  178.                 if (EqualString(work, PARM.fontName, FALSE, FALSE))
  179.                     break;
  180.             }
  181.             if (i <= nMenuItems) {
  182.                 GetDItem(
  183.                     theDialog,
  184.                     kSFItemFontPopupMenu,
  185.                     &itemType,
  186.                     &itemHandle,
  187.                     &itemRect
  188.                 );
  189.                 SetCtlValue((ControlHandle) itemHandle, i);
  190.             }
  191.             /*
  192.              * Set the font size popup menu
  193.              */
  194.             GetFNum(PARM.fontName, &parmFontNum);
  195.             nMenuItems = CountMItems(gFontSizeMenu);
  196.             NumToString(PARM.fontSize, fontSizeText);
  197.             selectedSize = 0;
  198.             for (i = 1; i <= nMenuItems; i++) {
  199.                 GetItem(gFontSizeMenu, i, work);
  200.                 if (EqualString(work, fontSizeText, FALSE, FALSE))
  201.                     selectedSize = i;
  202.             }
  203.             if (selectedSize != 0) {
  204.                 GetDItem(
  205.                     theDialog,
  206.                     kSFItemFontSizePopupMenu,
  207.                     &itemType,
  208.                     &itemHandle,
  209.                     &itemRect
  210.                 );
  211.                 SetCtlValue((ControlHandle) itemHandle, selectedSize);
  212.             }
  213.             break;
  214.         case kSFItemEnabledCheckBox:
  215.             GetDItem(
  216.                 theDialog,
  217.                 kSFItemEnabledCheckBox,
  218.                 &itemType,
  219.                 &itemHandle,
  220.                 &itemRect
  221.             );
  222.             SetCtlValue(
  223.                 (ControlHandle) itemHandle,
  224.                 1 - GetCtlValue((ControlHandle) itemHandle)
  225.             );
  226.             break;
  227.         case kSFSaveButton:
  228.         case kSFCancelButton:
  229.             /*
  230.              * Exit: get the audit selector, even if the user hit the "Cancel"
  231.              * button. SFPPutFile will still return reply->good == FALSE if the
  232.              * file isn't to be created.
  233.              */
  234.             GetDItem(
  235.                 theDialog,
  236.                 kSFItemSelectorTextEdit,
  237.                 &itemType,
  238.                 &itemHandle,
  239.                 &itemRect
  240.             );
  241.             GetIText(itemHandle, work);
  242.             PARM.auditIdent = 0;
  243.             for (i = work[0] + 1; i <= 4; i++)
  244.                 work[i] = 0;
  245.             if (work[0] != 4)
  246.                 work[0] = 4;
  247.             BlockMove(&work[1], &PARM.auditIdent, 4);
  248.             /*
  249.              * Get the number of log records.
  250.              */
  251.             GetDItem(
  252.                 theDialog,
  253.                 kSFItemLogLinesTextEdit,
  254.                 &itemType,
  255.                 &itemHandle,
  256.                 &itemRect
  257.             );
  258.             GetIText(itemHandle, work);
  259.             StringToNum(work, &PARM.auditRecords);
  260.             /*
  261.              * Get the number of lines.
  262.              */
  263.             GetDItem(
  264.                 theDialog,
  265.                 kSFItemAuditRecordsTextEdit,
  266.                 &itemType,
  267.                 &itemHandle,
  268.                 &itemRect
  269.             );
  270.             GetIText(itemHandle, work);
  271.             StringToNum(work, &PARM.logDisplayLines);
  272.             /*
  273.              * Get the checkbox status.
  274.              */
  275.             GetDItem(
  276.                 theDialog,
  277.                 kSFItemEnabledCheckBox,
  278.                 &itemType,
  279.                 &itemHandle,
  280.                 &itemRect
  281.             );
  282.             PARM.enableAudit = GetCtlValue((ControlHandle) itemHandle);
  283.             /*
  284.              * Get the font name
  285.              */
  286.             GetDItem(
  287.                 theDialog,
  288.                 kSFItemFontPopupMenu,
  289.                 &itemType,
  290.                 &itemHandle,
  291.                 &itemRect
  292.             );
  293.             i = GetCtlValue((ControlHandle) itemHandle);
  294.             GetItem(gFontMenu, i, PARM.fontName);
  295.             /*
  296.              * Get the font size
  297.              */
  298.             GetDItem(
  299.                 theDialog,
  300.                 kSFItemFontSizePopupMenu,
  301.                 &itemType,
  302.                 &itemHandle,
  303.                 &itemRect
  304.             );
  305.             i = GetCtlValue((ControlHandle) itemHandle);
  306.             GetItem(gFontSizeMenu, i, work);
  307.             StringToNum(work, &PARM.fontSize);
  308.         }
  309.         return (itemHit);
  310. }        
  311.  
  312.